package tgc.edu.tms.entity;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Transient;

import com.fasterxml.jackson.annotation.JsonIgnore;

import tgc.edu.tms.custom.BaseEntity;

@Entity  //教学计划制定表
public class EducationalPlanner extends BaseEntity<Integer>{
	private String qszc;			//起始周次
	private String jszc;			//结束周次
	private String jslx;			//安排-教室类型 多媒体教室
	private Teacher teacher;		//关联到教师表
	private Curriculum curriculum;	//人才方案录入
	private Schoolyear schoolyear;	//关联学年学期
	private List<TbClass> tbclass=new ArrayList<>();		//关联到班级
	private String searcherbanji;   //查询班级所用字段	
	private Boolean xmh;
	@JsonIgnore
	private List<ClassSchedule> schedule=new ArrayList<>();//对应生成的课程表 ClassSchedule表
	
	
	public Boolean getXmh() {
		return xmh==null?false:xmh;
	}

	public void setXmh(Boolean xmh) {
		this.xmh = xmh;
	}

	public String getSearcherbanji() {
		return searcherbanji;
	}

	public void setSearcherbanji(String searcherbanji) {
		this.searcherbanji = searcherbanji;
	}

	@ManyToMany()
	@JoinTable(name="educationalplanner_tbclass",joinColumns=@JoinColumn(name="ep_id"),inverseJoinColumns=@JoinColumn(name="taclass_id"))
	public List<TbClass> getTbclass() {
		return tbclass;
	}

	public void setTbclass(List<TbClass> tbclass) {
		this.tbclass = tbclass;
	}

	@ManyToOne
	public Teacher getTeacher() {
		return teacher;
	}

	public void setTeacher(Teacher teacher) {
		this.teacher = teacher;
	}

	@OneToMany(cascade=CascadeType.ALL,mappedBy="ep")
	public List<ClassSchedule> getSchedule() {
		return schedule;
	}

	public void setSchedule(List<ClassSchedule> schedule) {
		this.schedule = schedule;
	}
	@ManyToOne
	public Curriculum getCurriculum() {
		return curriculum;
	}

	public void setCurriculum(Curriculum curriculum) {
		this.curriculum = curriculum;
	}

	public String getQszc() {
		return qszc;
	}

	public void setQszc(String qszc) {
		this.qszc = qszc;
	}

	public String getJszc() {
		return jszc;
	}

	public void setJszc(String jszc) {
		this.jszc = jszc;
	}

	public String getJslx() {
		return jslx;
	}

	public void setJslx(String jslx) {
		this.jslx = jslx;
	}
	@ManyToOne
	public Schoolyear getSchoolyear() {
		return schoolyear;
	}

	public void setSchoolyear(Schoolyear schoolyear) {
		this.schoolyear = schoolyear;
	}
	@Transient
	public String getKcmc() {//课程名称
		return curriculum == null?null:curriculum.getKcmc();
	}
	@Transient
	public String getKcdm() {//课程代码
		return curriculum == null?null:curriculum.getKcdm();
	}
	@Transient
	public String getSkzc() {//上课周次
		return qszc == null&&jszc==null?null:qszc+'-'+jszc+'周';
	}
	@Transient
	public String getTeacherName() {//上课教师名字
		return teacher == null?null:teacher.getName();
	}
	@Transient
	public Float getXf() {//课程学分
		return curriculum == null?null:curriculum.getXf();
	}
	@Transient
	public String getKclb() {//课程类别
		return curriculum == null?null:curriculum.getKclb();
	}
	@Transient
	public String getKhfs() {//考核方式
		return curriculum == null?null:curriculum.getKhfs();
	}
	@Transient
	public Integer getZongxs() {//总学时
		return curriculum == null?null:curriculum.getZongxs();
	}
	@Transient
	public Integer getJsxs() {//讲授学时
		return curriculum == null?null:curriculum.getJsxs();
	}
	@Transient
	public Integer getSyxs() {//实验学时
		return curriculum == null?null:curriculum.getSyxs();
	}
	@Transient
	public Integer getSjxs() {//上机学时
		return curriculum == null?null:curriculum.getSjxs();
	}
	@Transient
	public Integer getQtxs() {//其他学时
		return curriculum == null?null:curriculum.getQtxs();
	}
	@Transient
	public Integer getZhouxs() {//周学时
		return curriculum == null?null:curriculum.getZhouxs();
	}
	@Transient
	public String getTeachername() {//上课教师
		return teacher == null?null:teacher.getName();
	}
	@Transient
	public String getXnxq() {//学年学期
		return schoolyear == null?null:schoolyear.getXnxq();
	}
	@Transient
	public String getXy() {//学院
		return curriculum == null?null:curriculum.getProfession().getCollege();
	}
	@Transient
	public String getZy() {//专业
		return curriculum == null?null:curriculum.getProfession().getProfesion();
	}
	@Transient
	public String getBj() {//班级
		String str="";
		for(TbClass c:tbclass) {
			str+=c.getName()+",";
		}
		String string = "" ;
		if(str.length()>0) {
			string =str.substring(0, str.length()-1);
		}
		return tbclass == null?null:string;
	}
	
	@Transient
	public List<Integer> getBjs() {
		List<Integer> list = new ArrayList<>();
		for (TbClass t : tbclass) {
			list.add(t.getId());
		}
		return list;
	}
	
	@Transient
	public Integer getTbclassNumbers() {	//上课人数
		Integer number = 0;
		if(getTbclass().size()>0&&getTbclass().get(0)!=null) {
			for (TbClass tbClass2 : getTbclass()) {
				number = number+tbClass2.getNumber();
			}
		}
		
		return number;
	}
}
